package cas;
/**
 * 09.12.2013 test program in the interview in CAS Software AG
 * I need to implement a binary tree.
 */

public class Node {
	private Node leftNode;
	private Node rightNode;
	private int value;

	public Node(int value) {
		this.value = value;
	}

	public void insertNode(int value) {
		if (value < this.value) {
			if (leftNode != null) {
				leftNode.insertNode(value);
			} else {
				leftNode = new Node(value);
			}
		} else {
			if (rightNode != null) {
				rightNode.insertNode(value);
			} else {
				rightNode = new Node(value);
			}
		}
	}

	public void printNode(Node root) {
		System.out.println("node: " + root.value);
		if (root.leftNode != null) {
			printNode(root.leftNode);
		}
		if (root.rightNode != null) {
			printNode(root.rightNode);
		}
	}

	public static void main(String args[]) {
		Node root = new Node(7);
		root.insertNode(5);
		root.insertNode(10);
		root.insertNode(3);
		root.insertNode(6);
		root.insertNode(7);
		root.insertNode(6);
		
		root.printNode(root);
	}
}
